package servlet;

import java.io.IOException;

import java.text.DateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.ReaderSerivice;

public class ReaderEdit extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	// TODO Auto-generated method stub
	int	rid=Integer.parseInt(req.getParameter("rid"));
	String	rname=req.getParameter("rname");
	rname=new String(rname.getBytes("ISO-8859-1"),"utf-8");
	String rcard=req.getParameter("rcard");
	String raddr=req.getParameter("raddr");
	raddr=new String(raddr.getBytes("ISO-8859-1"),"utf-8");
	String rtel=req.getParameter("rtel");
	double rmoney=0;
	if(req.getParameter("rmoney")!="")
    rmoney=Double.parseDouble(req.getParameter("rmoney"));
	
	Date time=new Date();
	 
	String rtime=DateFormat.getDateInstance().format(time);


	if(req.getParameter("rtime")!=null&&req.getParameter("rtime").trim().length()>0)
			rtime=req.getParameter("rtime");
			
		
	String uuser=req.getParameter("uuser");
	uuser=new String(uuser.getBytes("ISO-8859-1"),"utf-8");
	ReaderSerivice rs=new ReaderSerivice();
	rs.update(rid,rname, rcard, raddr, rtel, rmoney, rtime, uuser);
	req.getRequestDispatcher("/jsp/editReader.jsp").forward(req, resp);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
	doGet(req, resp);
	}
}
